package com.example.billw.interceptor;

import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;

/**
 * @Description TODO
 * @Author fantasy
 * @Date 2024/6/28 17:27
 **/

@Component
public class LoginInterceptor implements HandlerInterceptor {

    @Override
    public boolean preHandle(HttpServletRequest request, javax.servlet.http.HttpServletResponse response, Object handler) throws Exception {
        Object user = request.getSession().getAttribute("loginUser");
        if (user == null) {
//        if (false) {
            String contextPath = request.getContextPath();
            response.sendRedirect(contextPath);
            return false;
        } else {
            return true;
        }
    }
}
